package cn.saas.test;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Title :
 * @date : 2021/7/9 9:11
 */
public class HoleVoConvert implements PropertyConverter<List<HoleBean>, String> {

    @Override
    public List<HoleBean> convertToEntityProperty(String databaseValue) {
        if (databaseValue == null) return new ArrayList<>();
        TypeToken<List<HoleBean>> typeToken = new TypeToken<List<HoleBean>>() {
        };
        return new Gson().fromJson(databaseValue, typeToken.getType());
    }

    @Override
    public String convertToDatabaseValue(List<HoleBean> entityProperty) {
        if (entityProperty == null || entityProperty.size() == 0) {
            return "[]";
        } else {
            return new Gson().toJson(entityProperty);
        }
    }
}
